package au.com.bluelink.scjp.chap2;

public class StaticRedefineMethodTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		StaticParent sp = new StaticParent();
		// bad practice to use an object reference to call a static method
		// should use StaticParent.staticMethod();
		sp.staticMethod();
		sp.nonStaticMethod();

		StaticChild sc = new StaticChild();
		// bad practice to use an object reference to call a static method
		// should use StaticChild.staticMethod();
		sc.staticMethod();
		sc.nonStaticMethod();

		// NOTE: At runtime the spc.nonStaticMethod() select's the runtime
		// objects overridden version however the spc.staticMethod() selects the
		// reference implementation and not the runtime objects version.
		// ***** static methods can be redefined not overridden!!! *****
		StaticParent spc = new StaticChild();
		spc.staticMethod();
		spc.nonStaticMethod();
	}

}

class StaticParent {

	static void staticMethod() {
		System.out.println("In StaticParent's staticMethod");
	}

	void nonStaticMethod() {
		System.out.println("In StaticParent's nonStaticMethod");
	}

}

class StaticChild extends StaticParent {

	static void staticMethod() {
		// can NOT call super.staticMethod() because this method is redefined
		// not overridden
		System.out.println("In StaticChilds's staticMethod");
	}

	void nonStaticMethod() {
		// we can call super.nonStaticMethod() because this method is overriden
		System.out.println("In StaticChild's nonStaticMethod");
	}

}